#include<bits/stdc++.h>
#define int long long
#define N 1000005
#define ls (x<<1)
#define rs ((x<<1)|1)
#define mid ((l+r)>>1)
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
    while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int n,m,k;
int c[6705][6705];
int s[6705][6705];
int a[N];
const int mod=6661;
set<pair<pair<int,int>,pair<int,int> > > q;
void init(){
    for(int i=0;i<mod;i++){
        c[i][0]=s[i][0]=1;
        for(int j=1;j<=i;j++) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
    }
    for(int i=0;i<mod;i++)
        for(int j=1;j<mod;j++) s[i][j]=(s[i][j-1]+c[i][j])%mod; 
}
int Sum(int x,int y){
    int res=0;
    int u=(x/mod)%mod,v=x%mod;
    for(int i=1;i<=y/mod;i++) res=(res+c[u][i-1]*s[v][mod-1])%mod;
    res=(res+c[u][y/mod]*s[v][y%mod]%mod)%mod;
    return res;
}
int query(int x,int l,int r){
    return (Sum(x,r)-Sum(x,l-1)+mod)%mod;
}
signed main(){
    freopen("izumi.in","r",stdin);
    freopen("izumi.out","w",stdout);
    n=read();m=read();k=read();
    init();
    q.insert({{1,n},{k,1}});
    q.insert({{0,0},{0,0}});
    q.insert({{n+1,n+1},{0,0}});
    while(m--){
        int o,l,r,x;
        o=read();l=read();r=read();
        if(o==1){
            x=read();
            vector<pair<pair<int,int>,pair<int,int> > > f,g;
            for(auto it=prev(q.upper_bound({{l,0},{0,0}}));it!=q.end();it=next(it)){
                int L=(*it).first.first,R=(*it).first.second,X=(*it).second.first,Y=(*it).second.second;
                if(R<l) continue;
                if(L>r) break;
                f.push_back(*it);
                if(l<=L&&R<=r) continue;
                if(r<R) g.push_back({{r+1,R},{X,Y}});
                if(L<l) g.push_back({{L,l-1},{X,Y}});
            }
            for(auto i:f) q.erase(i);
            for(auto i:g) q.insert(i);
            q.insert({{l,r},{x,l}});
        }
        else{
            int sum=0;
            for(auto it=prev(q.upper_bound({{l,0},{0,0}}));it!=q.end();it=next(it)){
                int L=(*it).first.first,R=(*it).first.second,X=(*it).second.first,Y=(*it).second.second;
                if(R<l) continue;
                if(L>r) break;
                sum=(sum+query(X,max(L,l)-Y+1,min(R,r)-Y+1))%mod;
            }
            printf("%lld\n",sum);
        }
    }
    return 0;
}